$(function() {
	let sideimg = document.querySelector('.sideimg')
	let side = document.querySelector('.sideimg > img')
	let login = document.querySelector('.login')
	let box = document.querySelector('.box')
	let wang = document.querySelector('.wang')
	let but = document.querySelector('.loginBtn')
	let passwords = document.querySelector('.passwords')
	let title = document.querySelector('.title')
// 状态
	let is_login = true;
	let passTwoVal = true;
	let name = document.querySelector('#uname')
	let pass = document.querySelector('#upassword')
	let passTwo = document.querySelector('#passTwo')
	let codebtn = document.querySelector('.codebtn')
	let codebtnBtn = document.querySelector('.codebtn > button')
	let nameVal = null;
	let passVal = null;
	let passtwoVal = null;
	let email = null;
	let code = null
	let codebtnSpan = document.querySelector('.codebtn > span')
	let codebtnSSS = document.querySelector('.codebtn > button')

	sideimg.onclick = () => {
		switchFn()
	}

	function switchFn() {
		passTwoVal = is_login ? false : true
		title.innerText = is_login ? '欢迎注册' : '欢迎登录'
		wang.innerText = is_login ? '' : '忘记密码？'
		but.innerText = is_login ? '注册' : '登录'
		let loginAn = is_login ? 'login' : 'unlogin'
		let leftimg = is_login ? 'leftimg' : 'unleftimg'
		let offset = is_login ? '-45px' : '-65px'
		let imgSrc = is_login ? 'img/nillu.png' : 'img/ganyu_set.png'
		passwords.style.display = is_login ? 'block' : 'none'
		document.querySelector('.accountNumber').style.height = !is_login ? '30px' : '35px'
		document.querySelector('.accountNumber').style.marginTop = !is_login ? '30px' : '-20px'
		document.querySelector('.password').style.height = !is_login ? '70px' : '55px'
		document.querySelector('.password').style.marginTop = !is_login ? '50px' : '30px'
		document.querySelector('.accountNumber').style.marginBottom = !is_login ? '30px' : '0px'
		document.querySelector('.password').style.marginBottom = !is_login ? '30px' : '0px'
		// document.querySelector('.QQemial').style.display = is_login ? 'block' : 'none'
		// document.querySelector('.Code').style.display = is_login ? 'block' : 'none'
		// codebtn.style.display = is_login ? 'block' : 'none'
		but.style.marginTop = is_login ? '15px' : '65px'
		is_login = is_login ? false : true
		but.style.opacity = '0'
		side.style.opacity = '0'
		box.style.backdropFilter = 'blur(0px)'
		login.style.animation = `${loginAn} 2s`
		sideimg.style.animation = `${leftimg} 2s`
		login.style.animationFillMode = 'forwards'
		sideimg.style.animationFillMode = 'forwards'
		name.value = null
		pass.value = null
		passTwo.value = null
		setTimeout(() => {
			side.setAttribute('src', imgSrc);
			side.style.marginLeft = `${offset}`;
			side.style.opacity = '1';
			but.style.opacity = '1';
			box.style.backdropFilter = 'blur(5px)'
		}, 1000)
		$("#mySpan").empty();
	}
	name.onchange = () => {
		console.log(name.value)
		if(!is_login){
			$.ajax({
				url:"/AdminUser/checkName",
				data:{"uname":name.value},
				type:"post",
				dataType:"json",
				success:function (data){
					if (data){//data==true 用户名存在
						nameVal=null
						$("#mySpan").html("<img src='/img/no.png'/>用户名已经存在");
					}else {//用户名不存在
						nameVal = name.value
						$("#mySpan").html("<img src='/img/ok.png'/>");
					}
				}
			});
		}else{
			nameVal = name.value
		}
	}
	pass.onchange = () => {
		passVal = pass.value
	}
	passTwo.onchange = () => {
		passtwoVal = passTwo.value
		if (passVal == passtwoVal && passVal != null) {
			passTwoVal = true;
		}
	}

// 登录
	let loadicon = document.querySelector('.loadicon')
	let loadiconDiv = document.querySelector('.loadicon>div')
	let loadiconImg = document.querySelector('.loadicon>img')
	let loginValue = false
	function submitFun(){
		console.log("1212121:"+passTwoVal)
		if(nameVal != null && passVal != null && passTwoVal){
			console.log(is_login)
			loginValue = true
			return true
		}else {
			alert("请填写正确")
			return false
		}
	}
	$("#sub").click(function() {
		if (is_login) {
			$("#form").submit(function() {
				console.log(999)
				$(this).ajaxSubmit(function(data) {
					console.log(data)
				})
				return false
			})
		}else{
			$.ajax({
				url:"/user/regUser",
				data:{"uname":name.value,"upassword":pass.value},
				type:"post",
				dateType:"json",
				success:function (data){
					console.log(data)
					if (data.code==200){
						alert("注册成功，请登录！")
					}else{
						alert("注册失败！")
					}
				}
			})
			return false
		}


	})

// 注册
	function registerFn(vaule) {
		loadiconImg.setAttribute('src', 'img/registerZL.gif');
		loadiconDiv.innerText = '注册成功,请登录！'
		cloneFn(vaule)
	}
// 失败的方法
	function file() {
		loadiconImg.setAttribute('src', 'img/file.gif');
		cloneFn()
	}
// 归位
	function cloneFn(vaule) {
		setTimeout(() => {
			if (!is_login && vaule) {
				switchFn()
			}
			login.style.display = 'block';
			loadicon.style.display = 'none';
			loadiconImg.setAttribute('src', 'img/loadicon.gif');
			loadiconDiv.innerText = '登录中...'
		}, 1500)
	}
// 成功的方法
	function succcess() {
		setTimeout(() => {
			login.style.display = 'block';
			loadicon.style.display = 'none';
			// window.location = "http://127.0.0.1:8888/planBook/index.html";
		}, 500)
	}
})

